package com.itheima.d6_tcp3;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws IOException {
        final Socket socket = new Socket("192.168.49.11",8888);

        new Thread(()->{
            try {
                final DataInputStream dis = new DataInputStream(socket.getInputStream());

                final String s = dis.readUTF();
                System.out.println(s);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }).start();


        while (true) {
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入要发送的消息");

            String msg = scanner.nextLine();

            final OutputStream netOut = socket.getOutputStream();

            final DataOutputStream dos = new DataOutputStream(netOut);

            dos.writeUTF(msg);
            if(msg.equals("886")){
                break;
            }
        }
    }
}
